Skip to content

Pin decimal fast-path boundaries and reuse token characters - #1369

Merged
stevehu merged 2 commits into
masterfrom
fix/1368-decimal-fast-path-boundaries
Oct 24, 2026
Merged

stevehu merged 2 commits into
masterfrom
fix/1368-decimal-fast-path-boundaries

Conversation

@stevehu

@stevehu stevehu commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

The decimal parser's short-token limits and shortest-spelling comparison lacked checked-in regression coverage, and YAML could build the same numeric character array twice during one classification.

Reuse the character buffer locally within the token's precision decision, retaining lazy access for longer tokens. Add boundary tests, a fixed-seed 4,096-token classification oracle for JSON/YAML through both public mapper factories and NodeReader, upper-bound checks on classification getter requests (measured before Jackson tree binding), and nextNameMatch cache-invalidation coverage. Pin Jackson 3 YAML Core Schema's implicit string handling separately from explicit !!float numeric spellings. A short negative-token case pins retention of the leading-minus shortcut. Tag the new suite with jackson-upgrade. Character reuse is allocation hygiene; YAML timings reported in review on master were within noise, so no measured speedup is claimed.

Clarify that the existing performance table is historical output from a separate best-of-eight harness (JSON 200,000 elements, YAML 20,000), while the checked-in JMH benchmark defaults to 20,000 elements for both formats and uses a different measurement protocol.

Validation with Jackson 3.2.3:

  • mvn --batch-mode -Dstyle.color=never clean verify passed on Corretto 17.0.13, 21.0.5, and 25.0.3. Each run reported 10,568 tests, 30 skipped, zero failures/errors. All 11 new cases passed.
  • The upper-bound character-access regression still fails two cases against the original double-read code for JSON/YAML on this branch and passes with buffer reuse. Disallowing the leading minus also fails two cases. The tagged Jackson upgrade suite passed.
  • Eight mutation probes were detected: disallowing the leading minus, widening/narrowing the 15-digit limit, widening/narrowing the 16-character limit, disabling/inverting the shortest comparison, and removing nextNameMatch's cache reset. The temporary mutations were restored.
  • Diff whitespace checks passed.

Addresses #1368 on master; the companion 2.x PR #1370 provides the other supported Jackson line. Machine-double performance remains tracked in #1362. Remote CI passed for Java 17/21/25 and submit-maven.

@stevehu

stevehu commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Independent review of 4ea36af (scratch builds of the head and its merge base 878a27f). No correctness bugs found; remote CI is green (Java 17, 21, 25, submit-maven). I ran the tagged suite, not the full build or the full JDK matrix.

Verified

  • The jackson-upgrade suite (83 tests, including the 11 new Issue1368Test cases) passes on JDK 21.
  • No behaviour change: my per-token classification check (505,840 numbers in nested JSON/YAML documents) and exact-decimal oracle (54,000 checks) give 0 mismatches on the head and the base; the 304-schema count-limit probe is identical to the previous head.
  • The access-count test earns its keep: running Issue1368Test against the base SchemaNodeReader fails 2 cases.
  • Mutation check of the fast path (nine mutations, Issue1368Test + Issue1362Test): the digit limit +/-1, the length limit +/-1, the shortest comparison disabled, inverted, or ignoring the offset, and the dot requirement removed are each caught by 1 to 4 cases. One survives (finding 2).
  • Items in Pin short-decimal fast-path boundaries in the decimal-preserving parser #1368: boundary tests, nextNameMatch, the randomized oracle, the single getStringCharacters() call and the doc clarification are all covered.

Findings (all low severity)

  1. Exact access counts are brittle. shortcutAndShortestComparisonAvoidRepeatedTextMaterialization asserts exact getStringCharacters()/getString() counts on a counting delegate, and the class is tagged jackson-upgrade. The counts include whatever Jackson's tree builder reads through the wrapper, so a Jackson bump that reads token text slightly differently fails an upgrade check without a real regression, while a real regression that keeps the counts equal would pass. Upper bounds (at most one character read, no text read for the lossless cases) would keep the signal.
  2. The leading - in the shortcut is unpinned. Changing c != '.' && !(i == 0 && c == '-') to c != '.' sends negative short decimals through the slow path with identical node values, and no test fails: the only negative access case, -1234567890123.40, is 17 characters and takes the slow path by design. Please add an access-count case such as -123456789012.5.
  3. The YAML fix gives no measurable gain. NodeReader.readTree on a 20,000-element YAML array, best of 40 on master: plain floats 8.15 ms -> 7.72 ms, machine doubles 10.79 -> 10.76 ms, 19-digit decimals 15.22 -> 15.07 ms, short negatives 9.22 -> 8.66 ms (0 to 6 percent, within noise). Fine as hygiene, but the PR and Pin short-decimal fast-path boundaries in the decimal-preserving parser #1368 should not present it as a performance improvement; fetching the characters once at the top of the decision would also remove the nullable local.

🤖 Generated with Claude Code

@stevehu
stevehu merged commit b2ca3ea into master Oct 24, 2026
4 checks passed
@stevehu
stevehu deleted the fix/1368-decimal-fast-path-boundaries branch October 24, 2026 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant